//
// Created by 11510 on 2024/6/18.
//
#include <iostream>
#include <string>
#include <cmath>

using namespace std;

//#define PI 3.14

class Figure {
public:
    virtual string getName() const = 0;

    virtual double getArea() const = 0;
};

void display(Figure &fig) {
    cout << fig.getName()
         << "的面积是:"
         << fig.getArea() << endl;
}

class Rectangle : public Figure {
public:
    Rectangle(double len, double wid)
            : _length(len), _width(wid) {}

    string getName() const override {
        return "矩形";
    }

    double getArea() const override {
        return _length * _width;
    }

private:
    double _length;
    double _width;
};

class Circle : public Figure {
public:
    Circle(double r) : _radius(r) {}

    string getName() const override {
        return "圆形";
    }

    double getArea() const override {
        return PI * _radius * _radius;
    }

private:
    double _radius;
    /**
     * double 需要在运行时确定值，需要constexpr
     */
    static constexpr double PI = 3.1415926535;
};

class Triangle : public Figure {
public:
    Triangle(double a, double b, double c)
            : _a(a), _b(b), _c(c) {}

    string getName() const override {
        return "三角形";
    }

    double getArea() const override {
        double p = (_a + _b + _c) / 2;
        return sqrt(p * (p - _a) * (p - _b) * (p - _c));
    }

private:
    double _a, _b, _c;
};


void test0() {
    Rectangle rectangle(3, 2);
    Triangle triangle(3,4,5);
    Circle circle(2);

    display(rectangle);
    display(triangle);
    display(circle);


}

int main() {
    test0();
}
